package pl.edu.pw.perg.compinfodb.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Transactional;

import pl.edu.pw.perg.compinfodb.entities.HistoryItem;
import pl.edu.pw.perg.compinfodb.entities.PhysicalElement;
import pl.edu.pw.perg.compinfodb.entities.VirtualElement;

public class HistoryDAO extends GenericSpringDAO<HistoryItem> implements IHistoryDao {

	@Override
	public void deleteAll() {
		Query q = getSession().createQuery("delete from HistoryItem");
		q.executeUpdate();
	}
	public List<HistoryItem> findPhysicalElementHistory(PhysicalElement elementId) {
		Session s = getSession();
		List<HistoryItem> lst = findByCriteria(Restrictions.eq("physicalElement", elementId));
		return lst;
	}
	public List<HistoryItem> findVirtualElementHistory(VirtualElement element) {
		Session s = getSession();
		List<HistoryItem> lst = findByCriteria(Restrictions.eq("virtualElement", element));
		return lst;
	}
}
